import 'package:flame/game.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_demo/main.dart';
import 'package:go_router/go_router.dart';

import '../../pages/flame_example/flame_example.dart';
import '../../pages/settings/settings_page.dart';
import '../constants/app_route_constants.dart';

class AppRouter {
  static GoRouter returnRouter(bool isAuth) {
    final GoRouter router = GoRouter(
      initialLocation: '/home',
      routes: routeBase,
      redirect: (context, state) {
        if (!isAuth) {
          if (state.uri.toString() != '/login') {
            return '/login';
          }
        }
        return null;
        // No redirection if authenticated or already on the login route
      },
    );
    return router;
  }

  static List<RouteBase> routeBase = <RouteBase>[
    GoRoute(
      name: AppRouterConstants.homePage,
      path: '/home',
      builder: (context, state) => HomePage(),
    ),
    GoRoute(
      name: AppRouterConstants.themeSettingsPage,
      path: '/theme_settings',
      builder: (context, state) => const SettingsPage(),
    ),
    GoRoute(
      name: AppRouterConstants.flameExamplePage,
      path: '/flame_example',
      builder: (context, state) => Scaffold(
        appBar: AppBar(title: const Text('Flame例子')),
        body: GameWidget(
          game: FlameGame(world: MyWorld()),
        ),
      ),
    ),
  ];
}
